package mianshi;

import java.util.Scanner;

/**
 * @author cyt
 * @create 2020-05-15 10:36
 */
public class Test2 {

    private static void moveStr(String x[], int n) {
        n %= x.length;
        while (n > 0) {
            String temp = x[0];
            for (int i = 0; i < x.length - 1; i++) {
                x[i] = x[i + 1];
            }
            x[x.length - 1] = temp;
            n--;
        }
    }

    /**
     * 提前预处理数据
     *
     * @param args
     */
    public static void main(String args[]) {
        String A9[] = new String[]{"A", "B", "C", "D", "E", "F", "G", "H", "I"};
        String J9[] = new String[]{"J", "K", "L", "M", "N", "O", "P", "Q", "R"};
        String S9[] = new String[]{"S", "T", "U", "V", "W", "X", "Y", "Z", "*"};
        String main[] = new String[]{"A9", "J9", "S9"};

        Scanner sc = new Scanner(System.in);
        String date = sc.nextLine();
        String content = sc.nextLine();
        char[] contentArray = content.toCharArray();
        // 替换 空格换位*
        for (int i = 0; i < contentArray.length; i++) {
            if (contentArray[i] == ' ') {
                contentArray[i] = '*';
            }
        }
        int mon = Integer.parseInt(date.split("\\s+")[0]);
        int day = Integer.parseInt(date.split("\\s+")[1]);

		/*
		先根据月份数m， 移动(m-1)次。
		然后根据日期数d，移动(d-1)次
		*/
        int m = mon - 1;
        int d = day - 1;

        moveStr(main, m);
        int falgA = 0;
        int falgJ = 0;
        int falgS = 0;
        for (int i = 0; i < 3; i++) {
            if (main[i].contains("A"))
                falgA = i + 1;
            if (main[i].contains("J"))
                falgJ = i + 1;
            if (main[i].contains("S"))
                falgS = i + 1;
        }
        moveStr(A9, d);
        moveStr(J9, d);
        moveStr(S9, d);

        String str = "";
        for (int i = 0; i < contentArray.length; i++) {
            for (int j = 0; j < 9; j++) {
                if (String.valueOf(contentArray[i]).equals(A9[j]))
                    str += falgA + "" + (j + 1) + " ";
                if (String.valueOf(contentArray[i]).equals(J9[j]))
                    str += falgJ + "" + (j + 1) + " ";
                if (String.valueOf(contentArray[i]).equals(S9[j]))
                    str += falgS + "" + (j + 1) + " ";
            }
        }
        System.out.println(str);
    }
}
